#include "map.h"
using namespace mapscreen;
/*
int fpSelfTest(int, char*[]);
class testDraw : public Gtk::DrawingArea {
public:
    testDraw() {
        u = new Units::unit();
        u->place(2, 2);
        u->face(Units::up);
        u->sForm(Units::Siege);
        fp = new fleetpixel(u);
        set_can_focus(true);
    }
protected:
    void draw() {
        //grab the window
        Glib::RefPtr<Gdk::Window> window = get_window();
        if (!window) return;
        Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
        //window size info
        Gtk::Allocation allocation = get_allocation();
        const int width = allocation.get_width();
        const int height = allocation.get_height();
        cr->save();
        cr->set_source_rgb(.1, .1, .1);
        cr->rectangle(0, 0, width, height);
        cr->fill();
        cr->set_source_rgb(0,.4,0);
        for(int i = 0; i < height; i += pixHgt){
            cr->move_to(i, 0);
            cr->line_to(i, height);
            cr->stroke();
        }
        for(int j = 0; j < width; j += pixWid){
            cr->move_to(0,j);
            cr->line_to(width, j);
            cr->stroke();
        }
        fp->draw(u->posX(), u->posY(), cr);
        cr->restore();
    }
    bool on_expose_event(GdkEventExpose* exp) {
        draw();
        return false;
    }
    bool on_key_press_event(GdkEventKey* key) {
        draw();
        return false;
    }
private:
    fleetpixel* fp;
    Units::unit* u;
};
int main(int argc, char* argv[]) {
    return fpSelfTest(argc, argv);
}
int fpSelfTest(int argc, char* argv[]) {
    Gtk::Main kit(argc, argv);
    Gtk::Window *mwin = new Gtk::Window();
    Gtk::DrawingArea *drawme = new testDraw();
    drawme->set_visible(true);
    mwin->add(*drawme);
    kit.run(*mwin);
    return 0;
}*/
/* fleetPixel--------------------------
 * draws the fleet and its various attributes
 * ----------------------------------*/
const double fleetpixel::left = -3.14159 / 2;
const double fleetpixel::right = 3.14159 / 2;
const double fleetpixel::down = 3.144159;
fleetpixel::fleetpixel(Units::unit* u) {
    rep = u;
}
void fleetpixel::draw(int x, int y, ctype ct) {
    x = rep->posX() * pixWid;
    y = rep->posY() * pixHgt;
    ct->save();
    ct->translate(x, y);
    switch(rep->face()){
        case Units::left:
            ct->rotate(left);
            break;
        case Units::right:
            ct->rotate(right);
            break;
        case Units::down:
            ct->rotate(down);
            break;
    }
    if (rep->owner() == stalemateMain::controll::gsControll()->gPlayers()->gCurrentPlayerId()) {
        ct->set_source_rgb(.5, 1, .2);
    } else {
        ct->set_source_rgb(.81, .6, .13);
    }
    if (selx == x && sely == y && seled) {
        drawFArcs(x, y, ct);
    }
    switch (rep->gForm()) {
        case Units::standard:
            drawTriangle(x, y, ct);
            break;
        case Units::spindle:
            drawSpindle(x, y, ct);
            break;
        case Units::broad:
            drawBroad(x, y, ct);
            break;
        case Units::Aril:
            drawArtl(x, y, ct);
            break;
        case Units::Siege:
            drawSiege(x, y, ct);
            break;
    }
    ct->restore();
}
void fleetpixel::drawFArcs(int x, int y, ctype ct) {
    ct->save();
    uiterType uitr;
    int mnrange = 0, mxrange = 0;
    for (int j = Units::maxBat; j >= 0; j--) {
        uitr = rep->unititer();
        mnrange = uitr->first->gbattery((Units::bateryType)j)->minRange();
        mxrange = uitr->first->gbattery((Units::bateryType)j)->maxRange();
        for (int i = 0; i < rep->sunits(); i++, uitr++) {
            if (uitr->first->gbattery((Units::bateryType)j)->minRange() < mnrange)
                mnrange = uitr->first->gbattery((Units::bateryType)j)->minRange();
            if (uitr->first->gbattery((Units::bateryType)j)->maxRange())
                mxrange = uitr->first->gbattery((Units::bateryType)j)->maxRange();
        }
    }
    ct->restore();
}
void fleetpixel::drawSpindle(int x, int y, ctype ct) {
    ct->save();
    ct->move_to(0, -(pixHgt / 2));
    ct->line_to(-(pixWid / 6), (pixHgt / 3));
    ct->line_to((pixWid / 6), (pixHgt / 3));
    ct->close_path();
    ct->fill();
    ct->restore();
}
void fleetpixel::drawTriangle(int x, int y, ctype ct) {
    ct->save();
    ct->move_to(0, -(pixHgt / 4));
    ct->line_to(-(pixWid / 4), (pixHgt / 4));
    ct->line_to((pixWid / 4), (pixHgt / 4));
    ct->close_path();
    ct->fill();
    ct->restore();
}
void fleetpixel::drawBroad(int x, int y, ctype ct) {
    ct->save();
    ct->rectangle(-(pixWid / 2), -(pixHgt / 4), pixWid, 2 *pixHgt / 4);
    ct->fill();
    ct->restore();
}
void fleetpixel::drawArtl(int x, int y, ctype ct) {
    ct->save();
    ct->arc(0,0,pixHgt / 3, 0, 2 * 3.14159);
    ct->close_path();
    ct->fill();
    ct->restore();
}
void fleetpixel::drawSiege(int x, int y, ctype ct) {
    ct->save();
    ct->move_to(-pixWid / 2, -pixHgt / 4);
    ct->curve_to(-pixWid/3, pixHgt/3,
        pixWid/3, pixHgt/3,
        pixWid / 2, -pixHgt / 4);
    ct->curve_to(pixWid / 3, 0,
        -pixWid / 3, 0,
        -pixWid / 2, -pixHgt / 4);
    ct->close_path();
    ct->fill();
    ct->restore();
}
void fleetpixel::signal_curs_move(int x, int y) {

}
void fleetpixel::signal_curs_enter(int x, int y) {

}